<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title><{:C('web_site_name')}>---角色添加</title>
<link rel="stylesheet" type="text/css" href="<?php echo APP_TMPL_PATH ; ?>/static/css/common.css"/>
<link rel="stylesheet" type="text/css" href="<?php echo APP_TMPL_PATH ; ?>/static/css/main.css"/>
<script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/jquery.js"></script>
<script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/layer/lib.js"></script>
<script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/layer/layer.min.js"></script>
</head>

<body>


<form action="<?php echo  U("role/edit" , array('action'=>'doedit' ) ) ; ?>" method="post">
 <input type="hidden" name="id" value="<?php echo $info['id'];?>">
<div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i>首页<span class="crumb-step">&gt;</span><span class="crumb-name">角色设置</span></div>
        </div>
        
        <div class="result-wrap">
            <div class="result-content">
                    <table class="insert-tab" width="100%">
                        <tbody>
                        <tr>
                        <th>温馨提示：</th>
                            <td style="color:red">
                            <marquee scrollAmount=4 height="30" width="300" onmouseover="stop()" onmouseout="start()">在你选择权限的时候，如果选择有权限必须选择上一级有权限是选中的状态!! </marquee>     
                            </td>
                        </tr>
                            <tr>


                                <th><i class="require-red">*</i>角色名称：</th>
                                <td>
                                    <input class="common-text required" id="rolename" name="rolename" size="40" value="<?php echo $info['rolename'];?>" type="text"><i>必填</i>
                                </td>
                            </tr>
                            
                            <tr>
                                <th>状态：</th>
                                <td>
                               <input type="radio" name="status" value="1" <?php if($info['status'] == 1 ){echo "checked";}?>/> 启用
    <input type="radio" name="status" value="0" <?php if($info['status'] == 0 ){echo "checked";}?>/> 禁用
                                </td>
                            </tr>
                           <tr>
                             <?php 
    		if(isset($list) && $list){
				$perm_array = array();
				$perm_array = unserialize($info['perm']);
				$perm_array = empty($perm_array)?array():$perm_array;
				//print_r($perm_array);
					
    ?>
    
    <?php }?>
                                <th>权限如下：</th>
                                <td>
                               
                               <?php echo makeNavRole($list ,$perm_array);?>
                                </td>
                            </tr>   
                            <tr>
                                <th></th>
                                <td>
                                    <input id="btn" class="btn btn-primary btn6 mr10" value="提交" type="submit">
                                </td>
                            </tr>
                        </tbody></table>
            </div>
        </div>
       
      </form>  
    
   </body>
   </html>    
 <script>
function check_box(o){
    var path = $(o).attr("attr-path");
    var flag = $(o).find("input").attr("checked");
    paths=path.split("-"); //字符分割 
    var attr_id = $(o).attr("attr-id");
    var attr_pid = $(o).attr("attr-pid");
    var attr_path = $(o).attr("attr-path");
    for (i=0;i<paths.length ;i++ ) {
        //$("div[attr-id='"+paths[i]+"']").children("input").attr("checked" ,(flag)?false:true  ); ;
        //设置父元素的div颜色
        if(flag){
         // $("div[attr-id='"+paths[i]+"']").css("border-color","#CED9DF"); 
        }else{
        // $("div[attr-id='"+paths[i]+"']").css("border-color","red");    
        }
    }
    //设置子元素的状态和颜色
    var child_path = attr_path+"-"+attr_id;
    
    if(flag == 'checked'){//如果此时修改为不是选中的状态，修改子元素的颜色和checkbox的值
        //$("div[attr-path^='"+child_path+"']").css("border-color","#CED9DF");
        //$("div[attr-path^='"+child_path+"']").children("input").attr("checked" ,false ); 
    }
    //设置当前的div颜色
    if(flag){
        $(o).css("border-color","#CED9DF");
        $(o).find("input").attr("checked" , false ); 
    }else{
        $(o).css("border-color","red");
        $(o).find("input").attr("checked" , true  ); 
    }
    
}	
</script>
   
<?php 
    function makeNavRole($items , $perm_array){
        static $str = '' ;
       if(isset($items) && $items ){
            foreach($items as $k => $v ){
                $checked = '' ;

                $float = '' ;
                $color = '#CED9DF' ;
                if(in_array( $v['url'], $perm_array)){
                    $checked = 'checked'; 
                    $color = 'red' ;   
                }
                $list = explode("-" , $v['path']);
                $count = count($list) ;
				$prestr=str_repeat("├─", $count);
                $margin_left = $count*4+3;

                if($count == 4 ){
                    $float = 'float:left; ';
                }else{
                     $float = 'clear:both';
                 }
                
                $str.="<div style='{$float};width:290px ;border:solid 1px;border-color:{$color}; height:30px;line-height:30px;padding-left:4px;margin:4px;margin-left:{$margin_left}px;cursor:pointer' onclick='check_box(this)' attr-path='{$v['path']}'  attr-id='{$v['id']}' attr-pid='{$v['pid']}'>{$prestr}<input style='display:none' $checked type='checkbox'name='role[]' value='{$v['url']}'>{$v['name']}</div>";

                if(isset($v['items']) && $v['items'] ){
                    makeNavRole($v['items'],$perm_array);
                }
                
            }
       }
       return $str ;
    }
?>
        